<template>
  <div class="form-item-el">
    <div v-if="mode === 'DESIGN'">
      <el-input disabled :placeholder="placeholder" />
    </div>
    <div v-else-if="mode === 'PC' && !readonly">
      <el-input clearable v-model="_value" :placeholder="placeholder" :disabled="$attrs.disabled"></el-input>
    </div>
    <div v-else>
      {{ _value }}
    </div>
  </div>
</template>

<script setup>
import { computed, getCurrentInstance } from "vue";
import _ from "lodash";

const { proxy } = getCurrentInstance();
const props = defineProps({
  mode: {
    type: String,
    default: "DESIGN"
  },
  required: {
    type: Boolean,
    default: false
  },
  readonly: {
    type: Boolean,
    default: false
  },
  modelValue: {
    type: String,
    default: ""
  },
  placeholder: {
    type: String,
    default: "请输入内容"
  }
});
const emit = defineEmits(["update:modelValue"]);

const _value = computed({
  get() {
    return props.modelValue;
  },
  set(val) {
    emit("update:modelValue", val);
  }
});

if (_.isEmpty(_value.value) && !proxy.$attrs.disabled) {
  _value.value = proxy.$attrs.defaultValue;
}
</script>

<style lang="scss" scoped>
.text-input {
  width: 100%;
}
</style>
